package com.woniu.guoguo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.guoguo.model.Order;
import com.woniu.guoguo.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Richie
 * @since 2020-11-03
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where phone=#{username}")
    User findUserByUserName(String username);

    @Select("select * from user where phone=#{phone}")
    User getuser(String phone);

    @Insert("insert into user(phone,username,password,invitation_code) values (#{phone},#{username},#{password},#{invitecode})")
    int adduser(String phone, String username, String password,String invitecode);

    @Select("select * from user where user_id = #{userId}")
    User changeUser(int userId);

    @Update("update user set username = #{username},password = #{password},phone = #{phone},birthday = #{birthday} where user_id = #{userId}")
    void changeInfo(User user);

    @Select("select * from user where invitation_code = #{code}")
    User findinvite(String code);

    @Update("update user set upstream_user_id = #{upstreamUserId} where user_id = #{userId}")
    void addinvite(User user);

    @Select("select user_id,username,phone,birthday,vip,score,password,balance,upstream_user_id,invitation_code from user where user_id = #{userId}")
    User findbyuserid(int userId);

    //添加订单表
    @Insert("insert into `order` (user_id,description,price,shop_id,check_code,menu_id,out_trade_no) values (#{userId},#{description},#{price},#{shopId},#{checkCode},#{menuId},#{outTradeNo})")
    void addOrder(Order order);

    //修改用户余额
    @Update("update user set balance = balance - #{balance} where user_id = #{userId}")
    void changeblance(double balance,int userId);

    //修改商家余额
    @Update("update restaurant set income = income + #{income} where restaurant_id = #{shopId}")
    void changeshop(double income,int shopId);
}
